package com.jml.controller;

import com.jml.vo.Member;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

@Controller
public class MemberConsumerController extends AbstractBaseController {
	@Resource
	private RestTemplate restTemplate;

	@ApiOperation(value="获取指定编号人员信息" ,notes="传入mid就可获取人员信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name="mid",value="",required=true,dataType = "类型(随意写)")
	})
	@RequestMapping(value = "/consumer/get", method = RequestMethod.GET)
	public String getMember(long mid,Model model) {
		//第二个参数意思通过远程调用，将其 自动转化为相应的实例对象
		Member member = this.restTemplate.getForObject("http://localhost:8081/member/get/" + mid, Member.class);
		model.addAttribute("member", member) ;
		return "member_show";
	}


	@ApiOperation(value="该方法的作用" ,notes="对方法的说明")
	@ApiImplicitParams({
			@ApiImplicitParam(name="操作信息的名字",value="操作信息的具体内容",required=true,dataType = "类型(随意写)")
	})
	@RequestMapping(value = "/consumer/add", method = RequestMethod.GET)
	@ResponseBody
	public Object addMember(Member member) {
		Boolean flag = this.restTemplate.postForObject("http://localhost:8081/member/add", member, Boolean.class);
		return flag;
	}
}
